package com.browse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.common.domain.po.VideoBrowseRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * @author 路亚
 * @version 0.1
 * @className BrowseRecordMapper
 * @description
 * @date 2024/12/26 17:28
 * @since jdk11
 */
@Mapper
public interface BrowseRecordMapper extends BaseMapper<VideoBrowseRecord> {

    @Delete("delete from video_browse_record where id = #{id} and view_time != #{viewTime}")
    void removeById(VideoBrowseRecord videoBrowseRecord);


    @Update("CREATE TABLE video_browse_record_#{str} (\n" +
            "  `id` bigint NOT NULL COMMENT '主键',\n" +
            "  `user_id` bigint DEFAULT NULL COMMENT '用户id',\n" +
            "  `video_id` bigint DEFAULT NULL COMMENT '短剧id',\n" +
            "  `video_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '短剧名称',\n" +
            "  `video_image_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '短剧封面地址',\n" +
            "  `video_item_id` bigint DEFAULT NULL COMMENT '哪一集的id',\n" +
            "  `video_item_num` int DEFAULT NULL COMMENT '第几集',\n" +
            "  `video_item_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '这一集的观看地址',\n" +
            "  `view_time` datetime DEFAULT NULL COMMENT '观看时间',\n" +
            "  PRIMARY KEY (`id`) USING BTREE,\n" +
            "  UNIQUE KEY `video_index` (`video_id`) USING BTREE\n" +
            ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;")
    void createTable(@Param("str") Integer str);
}
